﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace haber
{
    public partial class anket : System.Web.UI.Page
    {
        public static string GetSiteRoot()
        {
            string port = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
            if (port == null || port == "80" || port == "443")
                port = "";
            else
                port = ":" + port;

            string protocol = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];
            if (protocol == null || protocol == "0")
                protocol = "http://";
            else
                protocol = "https://";

            string sOut = protocol + System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + port + System.Web.HttpContext.Current.Request.ApplicationPath;

            if (sOut.EndsWith("/"))
            {
                sOut = sOut.Substring(0, sOut.Length - 1);
            }

            return sOut;
        }
        int hi = -1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["akid"] != null)
            {
            
                if (int.TryParse(Request["akid"], out hi))
                {

                    using (dcHaberDataContext dc = new dcHaberDataContext())
                    {

                        var anketKisi = from ak in dc.AnketKisis
                                        where ak.KisiID == hi
                                        select new
                                        {
                                            ak.ID,
                                            ak.Anketler.AnketAdi,
                                            ak.Anketler.AnketAciklamasi,
                                            ak.Kisiler.Ad,
                                            ak.Kisiler.Soyad,
                                            ak.Kisiler.Resim
                                        };


                        if (anketKisi.Count() > 0)
                        {
                            var anket = anketKisi.First();

                            Page p = this.Page;
                            p.Header.Description = anket.AnketAdi+ "  "+anket.Ad +" "+anket.Soyad;
                            HtmlMeta hm;
                            hm = new HtmlMeta();
                            hm.Name = "og:title";
                            hm.Content = anket.AnketAdi + " " + anket.Ad + " " + anket.Soyad;
                            Page.Header.Controls.AddAt(0, hm);


                            hm = new HtmlMeta();
                            hm.Name = "og:type";
                            hm.Content = "website";
                            Page.Header.Controls.AddAt(0, hm);

                            hm = new HtmlMeta();
                            hm.Name = "og:url";
                            hm.Content = GetSiteRoot() + "/anket.aspx?akid=" + anket.ID;
                            Page.Header.Controls.AddAt(0, hm);

                            hm = new HtmlMeta();
                            hm.Name = "og:image";
                            hm.Content = GetSiteRoot() + "/anketResim/" + anket.Resim;
                            Page.Header.Controls.AddAt(0, hm);


                            hm = new HtmlMeta();
                            hm.Name = "og:site_name";
                            hm.Content = "sosyalmedyahaber.org";
                            Page.Header.Controls.AddAt(0, hm);

                            hm = new HtmlMeta();
                            hm.Name = "fb:admins";
                            hm.Content = "689431045";
                            Page.Header.Controls.AddAt(0, hm);

                        }
                    }


                }
            }
            else if (Request["anket"] != null) 
            {
                if (int.TryParse(Request["anket"], out hi))
                {
                    using (dcHaberDataContext dc = new dcHaberDataContext())
                    {

                        var anketler = from ak in dc.Anketlers
                                    where ak.ID == hi
                                    select new
                                    {
                                        ak.ID,
                                        ak.AnketAdi,
                                        ak.AnketAciklamasi
                                    };
                        if (anketler.Count() > 0)
                        {
                            var anket = anketler.First();
                            Page p = this.Page;
                            p.Header.Description = anket.AnketAdi;
                            HtmlMeta hm;
                            hm = new HtmlMeta();
                            hm.Name = "og:title";
                            hm.Content = anket.AnketAdi;
                            Page.Header.Controls.AddAt(0, hm);


                            hm = new HtmlMeta();
                            hm.Name = "og:type";
                            hm.Content = "website";
                            Page.Header.Controls.AddAt(0, hm);

                            hm = new HtmlMeta();
                            hm.Name = "og:url";
                            hm.Content = GetSiteRoot() + "/anket.aspx?anket=" + anket.ID;
                            Page.Header.Controls.AddAt(0, hm);

                            //hm = new HtmlMeta();
                            //hm.Name = "og:image";
                            //hm.Content = GetSiteRoot() + "/anketResim/" + anket.Resim;
                            //Page.Header.Controls.AddAt(0, hm);


                            hm = new HtmlMeta();
                            hm.Name = "og:site_name";
                            hm.Content = "http://www.sosyalmedyahaber.org";
                            Page.Header.Controls.AddAt(0, hm);

                            hm = new HtmlMeta();
                            hm.Name = "fb:admins";
                            hm.Content = "689431045";
                            Page.Header.Controls.AddAt(0, hm);
                        }
                    }
                }
            }
            else if (Request["a"] != null)
            {
                string yil = Request["a"].ToString();
                Page p = this.Page;
                p.Header.Description = yil + " YILININ KENDİ DALLARINDA ÖNE ÇIKANLARI ";
                HtmlMeta hm;
                hm = new HtmlMeta();
                hm.Name = "og:title";
                hm.Content = yil + " YILININ KENDİ DALLARINDA ÖNE ÇIKANLARI "; ;
                Page.Header.Controls.AddAt(0, hm);


                hm = new HtmlMeta();
                hm.Name = "og:type";
                hm.Content = "website";
                Page.Header.Controls.AddAt(0, hm);

                hm = new HtmlMeta();
                hm.Name = "og:url";
                hm.Content = GetSiteRoot() + "/anket.aspx?a=" + yil;
                Page.Header.Controls.AddAt(0, hm);

                //hm = new HtmlMeta();
                //hm.Name = "og:image";
                //hm.Content = GetSiteRoot() + "/anketResim/" + anket.Resim;
                //Page.Header.Controls.AddAt(0, hm);


                hm = new HtmlMeta();
                hm.Name = "og:site_name";
                hm.Content = "http://www.sosyalmedyahaber.org";
                Page.Header.Controls.AddAt(0, hm);

                hm = new HtmlMeta();
                hm.Name = "fb:admins";
                hm.Content = "689431045";
                Page.Header.Controls.AddAt(0, hm);
            }
            
        }
    }
}